package br.com.mmm.javacenter.framework.view.taglib.helper;

import java.io.IOException;
import java.io.Writer;
import java.util.List;

import br.com.mmm.javacenter.framework.annotations.RenderComponent;
import br.com.mmm.javacenter.framework.configuration.IocController;
import br.com.mmm.javacenter.framework.dao.RepositoryBase;
import br.com.mmm.javacenter.framework.entity.EntidadeBase;

@RenderComponent({
	EntidadeBase.class
})
public class InputComboEntidadeBase extends Input{
	@Override
	public void before() throws IOException {
		setMaxLength(1);
	}
	public boolean beforeInput() throws IOException {
		RepositoryBase repositoryBase = (RepositoryBase) IocController.picoSetterContainer.getComponentInstanceOfType(RepositoryBase.class);
		writer.write("<select ");
		addAttributesDefault(writer);
		writer.write(">");
		repositoryBase.klass(getKlass());
		List<EntidadeBase<?>> lista = repositoryBase.listarTodos();
		for(EntidadeBase entidadeBase:lista){
			writer.write("<option ");
			writer.write(getAtributo("value", entidadeBase.getId()));
			writer.write(">");
			writer.write(entidadeBase.getDescricaoCombo());
			writer.write("</option>");
		}
		writer.write("</select>");
		return false;
	}
}
